package com.future.strategy;

public class Sorter<T> {

    public void selectSort(T[] arr, Comparetor comparetor) {
        for (int i = 0; i < arr.length - 1; i++) {
            int minIndex = i;
            for (int j = i + 1; j < arr.length; j++) {
                minIndex = comparetor.compareTo(arr[i], arr[j]) > 0 ? j : i;
            }
            if (i != minIndex) {
                swap(arr, i, minIndex);
            }
        }

    }

    private void swap(T[] arr, int i, int j) {
        T t = arr[i];
        arr[i] = arr[j];
        arr[j] = t;
    }

}
